use std::{collections::{HashMap, HashSet}, vec};

mod ddz_card;

use ddz_card::CardInfo as CardInfo;
fn main() {
    println!("Hello, world!");

    let mut byte_vec = b"Misssssssssissipppi".to_vec();
    byte_vec.dedup();//去重
    println!("{:?}", &byte_vec);

    let mut byte_vec = b"Misssssssssissipppi".to_vec();
    let mut seen = HashSet::new();
    byte_vec.retain(|r| seen.insert(*r));
    println!("{:?}", &byte_vec);

    let mut int_vec:Vec<i32>= (1..=100).collect();
    println!("{:?}", int_vec);
    let ret:Vec<_> = int_vec.windows(2).map(|r| r[0] ^ r[1]).collect();
    println!("{:?}", ret);
    ret.iter().for_each(|r| print!("{} ", r));
    println!("");
    let index = 60;
    println!("ret len ={}, ret[{}]={}, int_vec.len={}" , ret.len(), index , ret[index], int_vec.len());

    for _i in 0..int_vec.len() {
        print!("{} ", int_vec.swap_remove(int_vec.len()-1));
    }


    println!("");
    println!("{:?}", int_vec);
    let val = ret.binary_search(&3);
    println!("val = {:?}, value ={}", val, ret[val.unwrap()]);
    let index = ret.iter().position(|x| *x == 63);
    println!("index = {:?}, value ={}", index, ret[index.unwrap()]);

    let mut my_vec = vec![1, 2, 3, 4, 5, 7, 9];
    println!("{:?}", my_vec);
    //只保留小于等于4的元素
    my_vec.retain(|x| *x <=4);
    println!("{:?}", my_vec);

    use rand::prelude::IteratorRandom;

    let user = "bigdata".to_string();
    let char_list ="01234#56789@abcdefghijk$%lmnopqrstuv^&wxyzABCDEF)_GHIJKLMNOPQ_+RSTUVWXYZ!@#$%^&*()_+";
    let sss = char_list.bytes().into_iter().choose_multiple(&mut rand::thread_rng(), 12);
    let password = String::from_utf8(sss).unwrap();
    println!("user ={}, password = {}", user, password);
    let card_map: HashMap<usize, CardInfo> = HashMap::from([
        (0 , CardInfo::new(2,1)),
        (1 , CardInfo::new(3,1)),
        (2 , CardInfo::new(4,1)),
        (3 , CardInfo::new(5,1)),
        (4 , CardInfo::new(6,1)),
        (5 , CardInfo::new(7,1)),
        (6 , CardInfo::new(8,1)),
        (7 , CardInfo::new(9,1)),
        (8 , CardInfo::new(10,1)),
        (9 , CardInfo::new(11,1)),
        (10 , CardInfo::new(12,1)),
        (11, CardInfo::new(13,1)),
        (12 , CardInfo::new(14,1)),
        (13 , CardInfo::new(2,2)),
        (14 , CardInfo::new(3,2)),
        (15 , CardInfo::new(4,2)),
        (16 , CardInfo::new(5,2)),
        (17 , CardInfo::new(6,2)),
        (18 , CardInfo::new(7,2)),
        (19 , CardInfo::new(8,2)),
        (20 , CardInfo::new(9,2)),
        (21 , CardInfo::new(10,2)),
        (22 , CardInfo::new(11,2)),
        (23 , CardInfo::new(12,2)),
        (24 , CardInfo::new(13,2)),
        (25 , CardInfo::new(14,2)),
        (26 , CardInfo::new(2,3)),
        (27 , CardInfo::new(3,3)),
        (28 , CardInfo::new(4,3)),
        (29 , CardInfo::new(5,3)),
        (30 , CardInfo::new(6,3)),
        (31 , CardInfo::new(7,3)),
        (32 , CardInfo::new(8,3)),
        (33 , CardInfo::new(9,3)),
        (34 , CardInfo::new(10,3)),
        (35 , CardInfo::new(11,3)),
        (36 , CardInfo::new(12,3)),
        (37 , CardInfo::new(13,3)),
        (38 , CardInfo::new(14,3)),
        (39 , CardInfo::new(2,4)),
        (40 , CardInfo::new(3,4)),
        (41 , CardInfo::new(4,4)),
        (42 , CardInfo::new(5,4)),
        (43 , CardInfo::new(6,4)),
        (44 , CardInfo::new(7,4)),
        (45 , CardInfo::new(8,4)),
        (46 , CardInfo::new(9,4)),
        (47 , CardInfo::new(10,4)),
        (48 , CardInfo::new(11,4)),
        (49 , CardInfo::new(12,4)),
        (50 , CardInfo::new(13,4)),
        (51 , CardInfo::new(14,4)),
        (52, CardInfo::new(0,0)),
        (53 , CardInfo::new(1,0))
    ]);
    for index in 0..ddz_card::CARD_NUM {
        println!("{}:{}", index, card_map.get(&index).unwrap());
    }

}
